package com.ruoyi.web.controller.blog;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.blog.domain.BizArticleLove;
import com.ruoyi.blog.service.IBizArticleLoveService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 喜爱标记Controller
 * 
 * @author wsa
 * @date 2019-10-20
 */
@Controller
@RequestMapping("/blog/love")
public class BizArticleLoveController extends BaseController
{
    private String prefix = "blog/love";

    @Autowired
    private IBizArticleLoveService bizArticleLoveService;

    @RequiresPermissions("blog:love:view")
    @GetMapping()
    public String love()
    {
        return prefix + "/love";
    }

    /**
     * 查询喜爱标记列表
     */
    @RequiresPermissions("blog:love:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(BizArticleLove bizArticleLove)
    {
        startPage();
        List<BizArticleLove> list = bizArticleLoveService.selectBizArticleLoveList(bizArticleLove);
        return getDataTable(list);
    }

    /**
     * 导出喜爱标记列表
     */
    @RequiresPermissions("blog:love:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(BizArticleLove bizArticleLove)
    {
        List<BizArticleLove> list = bizArticleLoveService.selectBizArticleLoveList(bizArticleLove);
        ExcelUtil<BizArticleLove> util = new ExcelUtil<BizArticleLove>(BizArticleLove.class);
        return util.exportExcel(list, "love");
    }

    /**
     * 新增喜爱标记
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存喜爱标记
     */
    @RequiresPermissions("blog:love:add")
    @Log(title = "喜爱标记", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(BizArticleLove bizArticleLove)
    {
        return toAjax(bizArticleLoveService.insertBizArticleLove(bizArticleLove));
    }

    /**
     * 修改喜爱标记
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        BizArticleLove bizArticleLove = bizArticleLoveService.selectBizArticleLoveById(id);
        mmap.put("bizArticleLove", bizArticleLove);
        return prefix + "/edit";
    }

    /**
     * 修改保存喜爱标记
     */
    @RequiresPermissions("blog:love:edit")
    @Log(title = "喜爱标记", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(BizArticleLove bizArticleLove)
    {
        return toAjax(bizArticleLoveService.updateBizArticleLove(bizArticleLove));
    }

    /**
     * 删除喜爱标记
     */
    @RequiresPermissions("blog:love:remove")
    @Log(title = "喜爱标记", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(bizArticleLoveService.deleteBizArticleLoveByIds(ids));
    }
}
